<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@page import="com.yaodian100.core.common.utils.ServerValue"%>
<head>
<style type="text/css">
h1 span{visibility:visible;}
td span{visibility:visible;}
.msg{float:left; line-height:1em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
.msg.rn{background-color:#fff2f2;border-color:#f66;}
</style>
</head>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath() %>'/>
<c-rt:set var="frontHostname" value='<%=ServerValue.getFrontHostname() %>'/>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<!-- 数字验证 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<!-- FLASH -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.flash.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/yaodian100.common.js"></script>
<script language="javascript">
	$().ready( function() {

		if('${error}'!=''){
			var err = "${error}".split(',');
			for(var i=1; i<=err.length; i++){
				$("#tab" + err[i-1] + "Tip").text("商品编号不存在");
				$("#tab" + err[i-1] + "Tip").show();
			}
		}
		
		$(":input[name*='ProdId']").each(function(){
			$("#" + this.id).numeric();
			$(this).blur(function(){
				$(this).val(prodPadLeft($(this).val()));
			});
		});
		
		$('#startDate').datepick({minDate: new Date(), showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"}); 
		$('#endDate').datepick({minDate: new Date(), showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"});
		$('#mainCate').hide();	
		$('#childCate').hide();
		
		$("#advType").change(function(){
			if ( this.value == "000_RDADV" ){
				$('#mainCate').show();
				$('#childCate').hide();
			}else if ( this.value == "100_RDADV" ){
				$('#mainCate').show();
				$('#childCate').show();
			}else{
				$('#mainCate').hide();
				$('#childCate').hide();
			}
		});

		
		if ( $("#advType").val() == "100_RDADV" || $("#advType").val() == "000_RDADV"){
			$('#mainCate').show();	
			$("#mainCate").val("${mainCateId}");
			if($("#advType").val() == "100_RDADV")
				$('#childCate').show();
			var childCateIds = "<option value=''>====== 请选择  ======</option>";
			$.getJSON("${midContextPath}/category/getProductCategory.do?type=json",
					{categoryid:$("#mainCateId").val()},
					function(categories){
						for(var i = 0 ; i < categories.length; i++ ){
							if ( "${childCateId}" == categories[i].id )
								childCateIds = childCateIds + "<option value='" + categories[i].id + "' selected='selected'>" + categories[i].name + "</option>";
							else
								childCateIds = childCateIds + "<option value='" + categories[i].id + "'>" + categories[i].name + "</option>";
						}
						$("#childCateId").find('option').remove().end();
						$("#childCateId").html(childCateIds);
					});
		}
		
			
		$("#mainCateId").change(function(){
			var childCateIds = "<option value=''>====== 请选择  ======</option>";
			if($("#mainCateId").val() != ''){
				$.getJSON("${midContextPath}/category/getProductCategory.do?type=json",
						{categoryid:$("#mainCateId").val()},
						function(categories){
							for(var i = 0 ; i < categories.length; i++ ){
								childCateIds = childCateIds + "<option value='" + categories[i].id + "'>" + categories[i].name + "</option>";
							}
							$("#childCateId").find('option').remove().end();
							$("#childCateId").html(childCateIds);
						});
			}else{
				$("#childCateId").find('option').remove().end();
				$("#childCateId").html(childCateIds);
			}
		});
		
		$("#subBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("10");
				$("#infoBroadcastAdvForm").submit();
			}
		});

		$("#draftBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("00");
				$("#infoBroadcastAdvForm").submit();
			}
		});
		
		$("#canBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("90");
				$("#infoBroadcastAdvForm").submit();
			}
		});
	});
	
	function validate_data(){
		var isCorrect = true;
		$("span:[id*=Tip]").hide();
		$("span:[id*=Tip]").text('');
		if ( $("#advName").val() == "" ){
			$("#advNameTip").text("请输入广告名称");
			$("#advNameTip").show();
			isCorrect = false;
		}

		if ( $("#startDate").val() == ""){
			$("#startDateTip").text("请输入起始时间");
			$("#startDateTip").show();
			isCorrect = false;
		}

		if( $("#endDate").val() == "" ){
			$("#endDateTip").text("请输入结束时间");
			$("#endDateTip").show();
			isCorrect = false;
		}
		
		if ( $("#advType").val() == "000_RDADV" || $("#advType").val() == "100_RDADV"){
			if ( $("#mainCateId").val() == "" ){
				$("#mainCateIdTip").text("请选择馆别");
				$("#mainCateIdTip").show();
				isCorrect = false;
			}
		}
		
		if ( $("#advType").val() == "100_RDADV"){
			if ( $("#childCateId").val() == "" ){
				$("#childCateIdTip").text("请选次分类");
				$("#childCateIdTip").show();
				isCorrect = false;
			}
		}

		for( var i = 1; i <= 3; i++ ){
			if ( $("#tab" + i + "ProdId").val() == ""){
				appendWord($("#tab" + i + "Tip"),"请输入商品编号");
				$("#tab" + i + "Tip").show();
				isCorrect = false;
			}else if ( $("#tab" + i + "ProdId").val() == "00000000"){
				appendWord($("#tab" + i + "Tip"),"商品编号错误");
				$("#tab" + i + "Tip").show();
				isCorrect = false;
			}
			for( var j = 1; j <=3; j++ ){
				if ( $("#advId").val() == "" ){
					if ( $("#tab" + i + "title" + j).val() == ""){
						appendWord($("#tab" + i + "Tip"),"请输入标题"+j);
						$("#tab" + i + "Tip").show();
						isCorrect = false;
					}
				}
				if ( $("#tab" + i + "title" + j +"Link").val() == ""){
					$("#tab" + i + "title" + j +"LinkTip").text("标题"+j+"点击连结不能空白");
					$("#tab" + i + "title" + j +"LinkTip").show();
					isCorrect = false;
				}else if ( !isURL($("#tab" + i + "title" + j +"Link").val()) ){
					$("#tab" + i + "title" + j +"LinkTip").text("标题"+j+"连结格式错误");
					$("#tab" + i + "title" + j +"LinkTip").show();
					isCorrect = false;
				}
			}		
		}
		
		return isCorrect;
	}

	function appendWord(origin, apptext){
		if(origin.text().length==0){
			origin.text(apptext);
		}else{
			origin.text(origin.text()+', '+apptext);
		}
		
	}
</script>
<s:actionerror />
<s:actionmessage />
<s:fielderror />
<h1>广告管理</h1>
<s:form action="infoBroadcast/saveInfoBroadcastAdv.do" method="post" name="infoBroadcastAdvForm" id="infoBroadcastAdvForm" enctype="multipart/form-data">
	<table class="tb-data" width="100%">
		<tbody>
			<tr>
				<th>类型</th>
				<td>
					<c-rt:if test="${advType eq '000_RDADV'}">馆首页 - 活动快讯/强力放送</c-rt:if>
					<c-rt:if test="${advType eq '100_RDADV'}">分类页 - 活动快讯/强力放送</c-rt:if>
					<input type="hidden" id="advType" name="advType" value="${advType}"/>
			</tr>
			<tr>
				<th>广告名称</th>
				<td><input type="text" id="advName" name="advName" value="${advName}" size="30" maxlength="30"/><br/><span id="advNameTip" class="msg rn" style="display:none;"></span></td>
			</tr>
			<tr>
				<th>馆别</th>
				<td>
					<div id="mainCate">
					<select id="mainCateId" name="mainCateId">
						<option value="">===请选择===</option>
						<c-rt:forEach items="${categoryRoot}" var="category">
							<option value="${category.id}" ${mainCateId eq category.id ? "selected" : ""}>${category.name}</option>
						</c-rt:forEach>
					</select>
					</div>
					<div id="childCate">
						<select id="childCateId" name="childCateId">
							<option value="">====== 请选择  ======</option>
						</select>
					</div>
					<span id="mainCateIdTip" class="msg rn" style="display:none;"></span>
					<span id="childCateIdTip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<th>起迄时间</th>
				<td>
				<input type="text" id="startDate" name="startDate" value="${startDate}" maxlength="10"/> ~ 
				<input type="text" id="endDate" name="endDate" value="${endDate}" maxlength="10"/><br/>
				<span id="startDateTip" class="msg rn" style="display:none;"></span>   <span id="endDateTip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<th>位置</th>
				<td>
					<select id="advTarget" name="advTarget">
						<option value="TOP"  ${advTarget eq "TOP" ? "selected" : ""}>活动快讯</option>
						<option value="BTM" ${advTarget eq "BTM" ? "selected" : ""}>强力放送</option>
					</select>
				</td>
			</tr>
			<tr>
				<th colspan="4">tab设定</th>
			</tr>
			<tr>
				<th>Tab1</th>
				<td>
					<b>商品编号:</b><input type="text" name="tab1ProdId" id="tab1ProdId" maxlength="8" size="10" value="${tab1ProdId}"/>（请输入商品编号）<br/>
					<b>标题一:</b><input type="text" name="tab1title1" id="tab1title1" maxlength="10" size="15" value="${tab1title1}"/><span class="txt-rd">字数限制:10个中文字</span><br/>
					<b>标题一点击连结:</b><input type="text" name="tab1title1Link" id="tab1title1Link" value="${tab1title1Link}" size="60"/><br/>
					<b>标题二:</b><input type="text" name="tab1title2" id="tab1title2" maxlength="10" size="15" value="${tab1title2}"/><span class="txt-rd">字数限制:10个中文字</span><br/>
					<b>标题二点击连结:</b><input type="text" name="tab1title2Link" id="tab1title2Link" value="${tab1title2Link}" size="60"/><br/>
					<b>标题三:</b><input type="text" name="tab1title3" id="tab1title3" maxlength="10" size="15" value="${tab1title3}"/><span class="txt-rd">字数限制:10个中文字</span><br/>
					<b>标题三点击连结:</b><input type="text" name="tab1title3Link" id="tab1title3Link" value="${tab1title3Link}" size="60"/><br/>
					<span id="tab1Tip" class="msg rn" style="display:none;"></span>
					<span id="tab1title1LinkTip" class="msg rn" style="display:none;"></span>
					<span id="tab1title2LinkTip" class="msg rn" style="display:none;"></span>
					<span id="tab1title3LinkTip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<th>Tab2</th>
				<td>
					<b>商品编号:</b><input type="text" name="tab2ProdId" id="tab2ProdId" maxlength="8" size="10" value="${tab2ProdId}"/>（请输入商品编号）<br/>
					<b>标题一:</b><input type="text" name="tab2title1" id="tab2title1" maxlength="10" size="15" value="${tab2title1}"/><span class="txt-rd">字数限制:10个中文字</span><br/>
					<b>标题一点击连结:</b><input type="text" name="tab2title1Link" id="tab2title1Link" value="${tab2title1Link}" size="60"/><br/>
					<b>标题二:</b><input type="text" name="tab2title2" id="tab2title2" maxlength="10" size="15" value="${tab2title2}"/><span class="txt-rd">字数限制:10个中文字</span><br/>
					<b>标题二点击连结:</b><input type="text" name="tab2title2Link" id="tab2title2Link" value="${tab2title2Link}" size="60"/><br/>
					<b>标题三:</b><input type="text" name="tab2title3" id="tab2title3" maxlength="10" size="15" value="${tab2title3}"/><span class="txt-rd">字数限制:10个中文字</span><br/>
					<b>标题三点击连结:</b><input type="text" name="tab2title3Link" id="tab2title3Link" value="${tab2title3Link}" size="60"/><br/>
					<span id="tab2Tip" class="msg rn" style="display:none;"></span>
					<span id="tab2title1LinkTip" class="msg rn" style="display:none;"></span>
					<span id="tab2title2LinkTip" class="msg rn" style="display:none;"></span>
					<span id="tab2title3LinkTip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>	
			<tr>
				<th>Tab3</th>
				<td>
					<b>商品编号:</b><input type="text" name="tab3ProdId" id="tab3ProdId" maxlength="8" size="10" value="${tab3ProdId}"/>（请输入商品编号）<br/>
					<b>标题一:</b><input type="text" name="tab3title1" id="tab3title1" maxlength="10" size="15" value="${tab3title1}"/><span class="txt-rd">字数限制:10个中文字</span><br/>
					<b>标题一点击连结:</b><input type="text" name="tab3title1Link" id="tab3title1Link" value="${tab3title1Link}" size="60"/><br/>
					<b>标题二:</b><input type="text" name="tab3title2" id="tab3title2" maxlength="10" size="15" value="${tab3title2}"/><span class="txt-rd">字数限制:10个中文字</span><br/>
					<b>标题二点击连结:</b><input type="text" name="tab3title2Link" id="tab3title2Link" value="${tab3title2Link}" size="60"/><br/>
					<b>标题三:</b><input type="text" name="tab3title3" id="tab3title3" maxlength="10" size="15" value="${tab3title3}"/><span class="txt-rd">字数限制:10个中文字</span><br/>
					<b>标题三点击连结:</b><input type="text" name="tab3title3Link" id="tab3title3Link" value="${tab3title3Link}" size="60"/><br/>
					<span id="tab3Tip" class="msg rn" style="display:none;"></span>
					<span id="tab3title1LinkTip" class="msg rn" style="display:none;"></span>
					<span id="tab3title2LinkTip" class="msg rn" style="display:none;"></span>
					<span id="tab3title3LinkTip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<input type="hidden" id="advId" name="advId" value="${advId}"/>
					<input type="hidden" id="advStatus" name="advStatus" value="${advStatus}"/>
					<input type="button" id="subBtn" name="subBtn" value="发送"/>
					<input type="button" id="draftBtn" name="draftBtn" value="草稿"/>
					<input type="button" id="canBtn" name="canBtn" value="暂停"/>
				</td>
			</tr>												
		</tbody>
	</table>
</s:form>
<div class="f-link">
	<a href="${midContextPath}/generate/cateMainProd/search.do">回广告查询页</a>
</div>